﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AceMobile.Models.Phones;
using AceMobile.Models;

namespace AceMobile.Controllers.Admin
{
    [Authorize(Roles = "Administrator,Phonemanager")]
    public class PhoneOSAdminController : Controller
    {
        private MobileWebContext db = new MobileWebContext();

        //
        // GET: /PhoneOSAdmin/

        public ViewResult Index()
        {
            return View(db.PhoneOSs.ToList());
        }

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /PhoneOSAdmin/Create

        [HttpPost]
        public ActionResult Create(PhoneOS phoneos)
        {
            if (ModelState.IsValid)
            {
                db.PhoneOSs.Add(phoneos);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(phoneos);
        }
        
        //
        // GET: /PhoneOSAdmin/Edit/5
 
        public ActionResult Edit(int id)
        {
            PhoneOS phoneos = db.PhoneOSs.Find(id);
            return View(phoneos);
        }

        //
        // POST: /PhoneOSAdmin/Edit/5

        [HttpPost]
        public ActionResult Edit(PhoneOS phoneos)
        {
            if (ModelState.IsValid)
            {
                db.Entry(phoneos).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(phoneos);
        }

        
        [HttpPost]
        public ActionResult Delete(int id)
        {
            try
            {
                PhoneOS phoneos = db.PhoneOSs.Find(id);
                db.PhoneOSs.Remove(phoneos);
                db.SaveChanges();
                return Json(new { status = "Success" });
            }
            catch (Exception)
            {
                return Json(new { status = "NotSuccess" });
            }              
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}